<template>
  <div>
    <div>
      <input type="text" v-model.trim="queryParams.schemaname"
             @keydown.enter="()=>{
      triggerSearch(queryParams.schemaname)
      }"
      />
      <button @click="()=>{
       triggerSearch(queryParams.schemaname)
      }"
      >查询
      </button>
      <button @click="()=>{
        triggerCopy(activeShema?.jsoncontent)
      }">复制json
      </button>
      <el-scrollbar style="height: 435px">
         <pre>
        {{ activeShema }}
      </pre>
      </el-scrollbar>

    </div>
  </div>
</template>
<script>
import axios from 'axios';

import { deepClone } from '@/utils';
import { lodashMap } from '@/utils/lodashUtil';
import { copyTextToClipboard } from '@/utils/clipboard';
import { alertSuccess } from '@base/utils';

export default {
  data() {
    return {
      activeShema: undefined,
      JSON: window.JSON,
      queryParams: {
        schemaname: '',
      },
    };
  },
  methods: {
    async triggerSearch(schemaname) {
      var one_rs = await axios.get(`/apis/swagger1/getshemasbyname?name=${this.queryParams.schemaname}`).then(res => res.data);
      var one = one_rs?.data;
      one.jsoncontent = JSON.parse(one?.jsoncontent);
      this.activeShema = one;
      console.log('=>[one]', one);
    },
    triggerCopy(_json) {
      var _json2 = deepClone(_json);
      var json3 = {};
      lodashMap(_json2, (value, key) => {
        json3[key] = '';
      });

      copyTextToClipboard(JSON.stringify(json3));
      alertSuccess('复制成功');
    },
  },
};
</script>
